﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EyFramework.ORM;
using Insurance.Entity;
using Insurance.Entity.Dto;

namespace Insurance.Core.Dao
{
    /// <summary>
    ///  INSU_VOUCHER表的数据库操作
    /// </summary>
    public class InsuVoucherDao : BaseDaoHis<InsuVoucher>, IInsuVoucherDao
    {
        public List<InsuVoucherDto> QueryVoucher(InsuVoucherParam insuVoucherParam)
        {
            string sql = @"select voucher_id, pat_name, id_no, decode(sex,'1','男','女') sex , card_no, card_id, voucher_str, insutype, psn_no, insu_date,(select zhigongxm from gy_zhigongxx where zhigonggh=a.create_by) create_by, create_time, update_by, update_time,
                        (select keshimc from HIS6.gy_keshi where keshiid=(select keshiid from his6.gy_zhigongxx where shenfenzh=a.id_no and zhigongxm=a.pat_name and rownum=1)) keshimc
                        from insu_voucher a where 1=1 ";
            if (string.IsNullOrEmpty(insuVoucherParam.PAT_NAME))
            {
                sql = sql + string.Format(" AND PAT_NAME LIKE '{0}%'", insuVoucherParam.PAT_NAME);
            }
            if (string.IsNullOrEmpty(insuVoucherParam.ID_NO))
            {
                sql = sql + string.Format(" AND ID_NO = '{0}'", insuVoucherParam.ID_NO);
            }
            sql = sql + " order by insu_date desc ";
            return Db.Ado.SqlQuery<InsuVoucherDto>(sql);
        }
    }
}